/*
* Copyright 2016 Yonyou Auto Information Technology（Shanghai） Co., Ltd. All Rights Reserved.
*
* This software is published under the terms of the YONYOU Software
* License version 1.0, a copy of which has been included with this
* distribution in the LICENSE.txt file.
*
* @Project Name : marketing-wechat-open-api
*
* @File name : PotentialUserController.java
*
* @Author : Administrator
*
* @Date : 2016年12月21日
*
----------------------------------------------------------------------------------
*     Date       Who       Version     Comments
* 1. 2016年12月21日    Administrator    1.0
*
*
*
*
----------------------------------------------------------------------------------
*/
	
package com.yonyou.gmcc.gateway.wechat.controller.customerinfo;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.marketing.common.dto.customerInfo.EditCarinfoDto;
import org.marketing.common.dto.customerInfo.MemberDto;
import org.marketing.common.dto.customerInfo.PushHistoryDto;
import org.marketing.common.dto.customerInfo.PotentialUserDto;
import org.marketing.common.util.CheckUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.yonyou.gmcc.gateway.wechat.common.ApiVersionConsts;
import com.yonyou.gmcc.gateway.wechat.controller.BaseController;
import com.yonyou.gmcc.gateway.wechat.controller.maintain.MaintainController;
import com.yonyou.gmcc.gateway.wechat.service.interfaces.PotentialUserServiceInterface;

/**
*
* @author Administrator
* TODO description
* @date 2016年12月21日
*/

@RestController
@RequestMapping(value = ApiVersionConsts.BASE_PATH+"/potentialUsers")
public class PotentialUserController extends BaseController{

    private static Logger logger = Logger.getLogger(MaintainController.class);
    
    @Autowired
    private PotentialUserServiceInterface potentialUserServiceInterface;
    
    /**
    * 个人中心信息查询
    * @author QianKun
    * @date 2016年12月21日
    * @param potentialUserId
    * @return
    * @throws Exception
    */
    @RequestMapping(method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public List<PotentialUserDto> getPersonalData(HttpServletRequest request, HttpServletResponse response)  throws Exception{
        List<PotentialUserDto> dtoList = null;
        try{
            Long potentialUserId = this.getPotentialUserId(request);
            logger.info("getPersonalData-potentialUserId="+potentialUserId);
            dtoList = potentialUserServiceInterface.getPersonalData(potentialUserId);
            if (CheckUtil.NullOrEmpty(dtoList)) {
                dtoList = new ArrayList<>();
            }
        }catch(Exception e){
            logger.error(e.getMessage(),e);
            throw e;
        }
        return dtoList;
    }
    
    /**
    * 个人中心头像查询
    * @author QianKun
    * @date 2016年12月21日
    * @param potentialUserId
    * @return
    * @throws Exception
    */
    @RequestMapping(value = "/personalPhoto",method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public List<PotentialUserDto> getPersonalPhoto(HttpServletRequest request, HttpServletResponse response)  throws Exception{
        List<PotentialUserDto> dtoList = null;
        try{
            Long potentialUserId = this.getPotentialUserId(request);
            logger.info("getPersonalData-potentialUserId="+potentialUserId);
            dtoList = potentialUserServiceInterface.getPersonalPhoto(potentialUserId);
            if (CheckUtil.NullOrEmpty(dtoList)) {
                dtoList = new ArrayList<>();
            }
        }catch(Exception e){
            logger.error(e.getMessage(),e);
            throw e;
        }
        return dtoList;
    }
    
    /**
    * 个人中心保险日期查询
    * @author QianKun
    * @date 2016年12月30日
    * @param vin
    * @return
    */
    @RequestMapping(value = "/personalInsure/{vin}", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public List<PotentialUserDto> getInsureData(@PathVariable("vin") String vin) {
        List<PotentialUserDto> dtoList = potentialUserServiceInterface.getInsureData(vin);
        if (CheckUtil.NullOrEmpty(dtoList)) {
            dtoList = new ArrayList<>();
        }
        return dtoList;
    }
    
    /**
    * 个人中心保养日期查询
    * @author QianKun
    * @date 2016年12月30日
    * @param vin
    * @return
    */
    @RequestMapping(value = "/personalMaintain/{vin}", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public List<PotentialUserDto> getMTData(@PathVariable("vin") String vin) {
        List<PotentialUserDto> dtoList = potentialUserServiceInterface.getMTData(vin);
        if (CheckUtil.NullOrEmpty(dtoList)) {
            dtoList = new ArrayList<>();
        }
        return dtoList;
    }
    
    /**
    * 爱车编辑页面查询
    * @author QianKun
    * @date 2017年1月12日
    * @param carId
    * @return
    */
    @RequestMapping(value = "/editCarinfo/{carId}", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public List<EditCarinfoDto> getCarInfoByCarId(@PathVariable("carId") String carId) {
        List<EditCarinfoDto> dtoList = potentialUserServiceInterface.getCarInfoByCarId(carId);
        if (CheckUtil.NullOrEmpty(dtoList)) {
            dtoList = new ArrayList<>();
        }
        return dtoList;
    }
    
    /**
    * 个人中心-我的消息列表查询
    * @author QianKun
    * @date 2017年1月16日
    * @param receiverId
    * @return
    */
    @RequestMapping(value = "/myMessage", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public List<PushHistoryDto> getMymessage(HttpServletRequest request, HttpServletResponse response) throws Exception{
        String receiverId = this.getOpenId(request);
        //String receiverId = "omLPIwAROJROvIo06uHBOp52atNQ";
        List<PushHistoryDto> dtoList = potentialUserServiceInterface.getMymessage(receiverId);
        if (CheckUtil.NullOrEmpty(dtoList)) {
            dtoList = new ArrayList<>();
        }
        return dtoList;
    }
    
    /**
    * 会员中心信息查询
    * @author QianKun
    * @date 2017年2月28日
    * @param request
    * @param response
    * @return
    * @throws Exception
    */
    @RequestMapping(value = "/memberInfo", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public List<MemberDto> getMemberInfo(HttpServletRequest request, HttpServletResponse response) throws Exception{
        //Long potentialUserId = (long)87;
        Long potentialUserId = this.getPotentialUserId(request);
        List<MemberDto> dtoList = potentialUserServiceInterface.getMemberInfo(potentialUserId);
        if (CheckUtil.NullOrEmpty(dtoList)) {
            dtoList = new ArrayList<>();
        }
        return dtoList;
    }
    
    /**
    * 更新会员信息(车主)
    * @author QianKun
    * @date 2017年3月1日
    * @param memberDto
    * @return
    * @throws Exception
    */
    @RequestMapping(value={"/updateCarOwnerInfo"},method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public Map<String,Object> updateCarOwnerInfo(@RequestBody MemberDto memberDto)throws Exception{
        Map<String,Object> map = potentialUserServiceInterface.updateCarOwnerInfo(memberDto);
        return map;
    }
    
    /**
    * 更新会员信息(潜客)
    * @author QianKun
    * @date 2017年3月1日
    * @param memberDto
    * @return
    * @throws Exception
    */
    @RequestMapping(value={"/updatePotentialInfo"},method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public Map<String,Object> updatePotentialInfo(@RequestBody MemberDto memberDto)throws Exception{
        Map<String,Object> map = potentialUserServiceInterface.updatePotentialInfo(memberDto);
        return map;
    }   
    
    /**
    * 更新会员信息(顾问)
    * @author QianKun
    * @date 2017年3月1日
    * @param memberDto
    * @return
    * @throws Exception
    */
    @RequestMapping(value={"/updateCounselorInfo"},method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public Map<String,Object> updateCounselorInfo(@RequestBody MemberDto memberDto)throws Exception{
        Map<String,Object> map = potentialUserServiceInterface.updateCounselorInfo(memberDto);
        return map;
    }
}
